function dQ = GetdQ_3CC(wm)

ss = size(wm,1);
if ss == 2
    t1 = wm(1,:)';  t2 = wm(2,:)';
    phi = t1 + t2 + 2/3*cross(t1,t2);
elseif ss == 3
    t1 = wm(1,:)';  t2 = wm(2,:)';  t3 = wm(3,:)';
    phi = t1 + t2 + t3 ...
          + 27/40*cross(t1,t2) + 9/20*cross(t1,t3)  + 27/40*cross(t2,t3) ...
          + 261/2240*cross3(t1,t1,t2) + 27/448*cross3(t1,t1,t3) + 603/1120*cross3(t1,t2,t3) ...
          - 207/1120*cross3(t2,t1,t2) - 603/2240*cross3(t2,t1,t3) + 207/1120*cross3(t2,t2,t3) ...
          - 27/448*cross3(t3,t1,t3) - 261/2240*cross3(t3,t2,t3);
elseif ss == 4
    t1 = wm(1,:)';  t2 = wm(2,:)';  t3 = wm(3,:)';  t4 = wm(4,:)';
    vec_dot = [t4 t3 t2 t1];
    c12 = [-489/1459 -694/1573 -753/3056   591/5179  ]';
    c13 = [-171/662  -109/3719  157/695    265/3934  ]';
    c14 = [-156/1571  249/1441  455/23834  156/1571  ]';
    c23 = [-113/235  -111/823   111/823    206/1901  ]';
    c24 = [-265/3934  247/1685  109/3719  1549/23321 ]';
    c34 = [-591/5179  753/3056  175/2547   491/3427  ]';
    A12 = vec_dot*c12; A13 = vec_dot*c13; A14 = vec_dot*c14;
    A23 = vec_dot*c23; A24 = vec_dot*c24; A34 = vec_dot*c34;
    phi = t1 + t2 + t3 + t4 ...
          + 232/315*cross(t3,t4) + 46/105*cross(t2,t4) + 18/35*cross(t1,t4)...
          + 178/315*cross(t2,t3) + 46/105*cross(t1,t3) + 232/315*cross(t1,t2)...
          + cross3(A12,t1,t2) + cross3(A13,t1,t3) + cross3(A14,t1,t4)...
          + cross3(A23,t2,t3) + cross3(A24,t2,t4) + cross3(A34,t3,t4);
elseif ss == 5
    t1 = wm(1,:)';  t2 = wm(2,:)';  t3 = wm(3,:)';  t4 = wm(4,:)';  t5 = wm(5,:)';
    phi = t1 + t2 + t3 + t4 + t5 ...
          + 232/315*cross(t3,t4) + 46/105*cross(t2,t4) + 18/35*cross(t1,t4) + 178/315*cross(t2,t3) + 46/105*cross(t1,t3) + 232/315*cross(t1,t2)...
          + 591/5179*cross3(t1,t1,t2) - 753/3056*cross3(t2,t1,t2) -  499/908*cross3(t3,t1,t2) - 457/1138*cross3(t4,t1,t2)...
          + 265/3934*cross3(t1,t1,t3) + 599/1792*cross3(t2,t1,t3) - 109/3719*cross3(t3,t1,t3) - 457/1138*cross3(t4,t1,t3)...
          + 156/1571*cross3(t1,t1,t4) + 409/4783*cross3(t2,t1,t4) + 769/2433*cross3(t3,t1,t4) - 156/1571*cross3(t4,t1,t4)...
          +  111/823*cross3(t2,t2,t3) -  111/823*cross3(t3,t2,t3) -  499/908*cross3(t4,t2,t3) + 109/3719*cross3(t2,t2,t4)...
          + 411/1909*cross3(t3,t2,t4) - 265/3934*cross3(t4,t2,t4) + 753/3056*cross3(t3,t3,t4) - 591/5179*cross3(t4,t3,t4);
elseif ss == 6
    t1 = wm(1,:)';  t2 = wm(2,:)';  t3 = wm(3,:)';  t4 = wm(4,:)';  t5 = wm(5,:)';  t5 = wm(5,:)';
    phi = t1 + t2 + t3 + t4 + t5 + t6 ...
          + 232/315*cross(t3,t4) + 46/105*cross(t2,t4) + 18/35*cross(t1,t4) + 178/315*cross(t2,t3) + 46/105*cross(t1,t3) + 232/315*cross(t1,t2)...
          + 591/5179*cross3(t1,t1,t2) - 753/3056*cross3(t2,t1,t2) -  499/908*cross3(t3,t1,t2) - 457/1138*cross3(t4,t1,t2)...
          + 265/3934*cross3(t1,t1,t3) + 599/1792*cross3(t2,t1,t3) - 109/3719*cross3(t3,t1,t3) - 457/1138*cross3(t4,t1,t3)...
          + 156/1571*cross3(t1,t1,t4) + 409/4783*cross3(t2,t1,t4) + 769/2433*cross3(t3,t1,t4) - 156/1571*cross3(t4,t1,t4)...
          +  111/823*cross3(t2,t2,t3) -  111/823*cross3(t3,t2,t3) -  499/908*cross3(t4,t2,t3) + 109/3719*cross3(t2,t2,t4)...
          + 411/1909*cross3(t3,t2,t4) - 265/3934*cross3(t4,t2,t4) + 753/3056*cross3(t3,t3,t4) - 591/5179*cross3(t4,t3,t4);
end

dQ = rv2q(phi);

end